﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NewsPub;
using NewLife.CommonEntity;
using NewLife.Web;

public partial class CommunicateDisp : MyPageBase<Communicate>
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        EntityForm.OnGetEntity += EntityForm_OnGetEntity;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Entity.ID == 0 & HttpContext.Current.Request["ReferenceNumber"]==null) Response.Redirect("Default.aspx");
            DataBind();
            string location;
            if (Entity.Classis.ParentID == 0)
            {
                location = "<a href='Default.aspx'>首页</a>&nbsp;&gt;&nbsp;<a href='"+Entity.ListUrl+"?id=" + Entity.Classis.ID + "'>" + Entity.Classis.Name + "</a>";
            }
            else
            {
                location = "<a href='Default.aspx'>首页</a>&nbsp;&gt;&nbsp;<a href='" + Entity.ListUrl + "?id=" + Entity.Classis.ParentID + "'>" + Entity.Classis.ParentClassisName + "</a>&nbsp;&gt;&nbsp;<a href='" + Entity.ListUrl + "?id=" + Entity.Classis.ParentID + "&sid=" + Entity.Classis.ID + "'>" + Entity.Classis.Name + "</a>";
            }
            Navigation.Text = location;
        }
        
    }
    void EntityForm_OnGetEntity(object sender, EntityFormEventArgs e)
    {
        NewLife.Log.XTrace.WriteLine("entity是不是空？" + (Entity==null).ToString());
        int id = WebHelper.RequestInt("id");
        NewLife.Log.XTrace.WriteLine("id=" + id);
        string rn = HttpContext.Current.Request["ReferenceNumber"];
        NewLife.Log.XTrace.WriteLine("ReferenceNumber=" + rn);
        if (id == 0)
        {

            NewLife.Log.XTrace.WriteLine("id==0查找到的rn:" + rn);
             Entity = Communicate.FindByReferenceNumber(rn);
             if (Entity == null) WebHelper.AlertAndRedirect("id==null错误的参数！", "default.aspx");
            
        }
        else
        {
            if (Entity == null) WebHelper.AlertAndRedirect("entity为空！", "default.aspx");
            NewLife.Log.XTrace.WriteLine("id=" + id + "查找到的rn:" + rn);
            if (Entity.ReferenceNumber != rn )
            {
                WebHelper.AlertAndRedirect("错误的参数！", "default.aspx");
            }
        }
        
    }
}